import 'package:casdon/modules/me/data/api/social_binded_list_api.dart';

class SocialBindedListState {
  static String KAppleSource = "APPLE";
  static String KWXSource = "WECHAT_OPEN";

  String? appleAuthId;
  String? wxAuthId;
  String? appleAccount;
  String? wxAccount;
  String? appleId; // 只是凯度平台存储的id， 并不是真的苹果id，用于解绑
  String? wxId; // 只是凯度平台存储的id， 并不是真的微信id， 用于解绑

  String? errorMsg;

  SocialBindedListState({
    this.appleAccount,
    this.wxAccount,
    this.appleAuthId,
    this.wxAuthId,
    this.appleId,
    this.wxId,
    this.errorMsg,
  });

  factory SocialBindedListState.initial() {
    return SocialBindedListState(
      appleAccount: null,
      wxAccount: null,
      appleAuthId: null,
      wxAuthId: null,
      appleId: null,
      wxId: null,
      errorMsg: null,
    );
  }

  // ✅ 私有标记对象
  static const Object _sentinel = Object();

  SocialBindedListState copyWith({
    Object? appleAccount = _sentinel,
    Object? appleAuthId = _sentinel,
    Object? wxAccount = _sentinel,
    Object? wxAuthId = _sentinel,
    Object? appleId = _sentinel,
    Object? wxId = _sentinel,
    Object? errorMsg = _sentinel,
  }) {
    return SocialBindedListState(
      appleAccount: _getValue(appleAccount, this.appleAccount),
      appleAuthId: _getValue(appleAuthId, this.appleAuthId),
      wxAccount: _getValue(wxAccount, this.wxAccount),
      wxAuthId: _getValue(wxAuthId, this.wxAuthId),
      appleId: _getValue(appleId, this.appleId),
      wxId: _getValue(wxId, this.wxId),
      errorMsg: _getValue(errorMsg, this.errorMsg),
    );
  }

  // ✅ 类型安全取值
  T? _getValue<T>(Object? newValue, T? currentValue) {
    return newValue == _sentinel ? currentValue : newValue as T?;
  }
}
